package myPetStore.service;

import myPetStore.domain.Account;
import myPetStore.persistence.AccountDao;
import myPetStore.persistence.impl.AccountImpl;

public class AccountService {
    private AccountDao accountDao;

    public AccountService(){
        this.accountDao=new AccountImpl();
    }
    public Account getAccountByEmail(String email){
        return accountDao.getAccountByEmail(email);
    }
    public Account getAccount(String username, String password) {
        Account account = new Account();
        account.setUsername(username);
        account.setPassword(password);
        return accountDao.getAccountByUsernameAndPassword(account);
    }
    public boolean usernameIsExist(String username){
        return accountDao.isUsernameExist(username);
    }
    public boolean addAccount(Account account){
        //TODO 把除了注册时输入的信息的属性补充完整
        initAccount(account);
        accountDao.insertAccount(account);
        accountDao.insertProfile(account);
        accountDao.insertSignon(account);
        return true;
    }
    public boolean changeAccount(Account account){
        //TODO 把除了注册时输入的信息的属性补充完整
        initAccount(account);
        accountDao.updateAccount(account);
        accountDao.updateProfile(account);
        accountDao.updateSignon(account);
        return true;
    }

    private void initAccount(Account account){
        account.setLanguagePreference("english");
        account.setStatus("OK");
        account.setListOption(true);
        account.setBannerOption(true);
//        account.setBannerName();
    }
}
